package pers.yurwisher.rubick.manager.service.impl;

import cn.hutool.core.lang.Assert;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pers.yurwisher.rubick.common.base.impl.BaseServiceImpl;
import pers.yurwisher.rubick.common.wrapper.PageR;
import pers.yurwisher.rubick.manager.entity.SystemFaq;
import pers.yurwisher.rubick.manager.mapper.SystemFaqMapper;
import pers.yurwisher.rubick.manager.pojo.fo.SystemFaqFo;
import pers.yurwisher.rubick.manager.pojo.qo.SystemFaqQo;
import pers.yurwisher.rubick.manager.pojo.to.SystemFaqTo;
import pers.yurwisher.rubick.manager.pojo.vo.SystemFaqVo;
import pers.yurwisher.rubick.manager.service.ISystemFaqService;

/**
 * @author yq
 * @date 2021-03-03 11:07:55
 * @description FAQ常见问题解答
 * @since V1.0.0
 */
@Service
public class SystemFaqServiceImpl extends BaseServiceImpl<SystemFaqMapper, SystemFaq> implements ISystemFaqService {

    /**
     * 新增
     * @param fo 参数
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(SystemFaqFo fo){
        SystemFaq systemFaq = new SystemFaq();
        BeanUtils.copyProperties(fo,systemFaq);
        baseMapper.insert(systemFaq);
    }

    /**
     * 更新
     * @param id 主键
     * @param fo 参数
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(Long id,SystemFaqFo fo){
        SystemFaq systemFaq = baseMapper.selectById(id);
        Assert.notNull(systemFaq);
        BeanUtils.copyProperties(fo,systemFaq);
        baseMapper.updateById(systemFaq);
    }

    /**
     * 列表
     * @param qo 查询参数
     * @return 分页对象
     */
    @Override
    @SuppressWarnings("unchecked")
    public PageR<SystemFaqTo> list(SystemFaqQo qo){
        return super.toPageR(baseMapper.list(super.toPage(qo),qo));
    }


    /**
    * 详情
    * @param id 主键
    * @return SystemFaqVo
    */
    @Override
    public SystemFaqVo get(Long id){
        return baseMapper.get(id);
    }

     /**
     * 删除
     * @param id 主键
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Long id){
        baseMapper.deleteById(id);
    }
}
